package controllers

import (
	"gdshop-font-api-go/app/request/GoodsReq"
	"gdshop-font-api-go/app/service/GoodsService"
	"gdshop-font-api-go/library/response"
	"gdshop-font-api-go/library/tools/token"
	"github.com/gogf/gf/net/ghttp"
)

type GoodsController struct {
	*BaseController
}

// 商品列表
func (c *GoodsController) List(r *ghttp.Request) *response.JsonResponse {
	var parames *GoodsReq.List
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = token.GetLoginMemberId(r)
	return GoodsService.List(r.GetCtx(), parames)
}

// 商品详情
func (c *GoodsController) Details(r *ghttp.Request) *response.JsonResponse {
	var parames *GoodsReq.Details
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	token.CheckToken(r)
	parames.MemberId = token.GetLoginMemberId(r)
	return GoodsService.Details(r.GetCtx(), parames)
}

// 商品正文
func (c *GoodsController) Content(r *ghttp.Request) *response.JsonResponse {
	var parames *GoodsReq.Content
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = token.GetLoginMemberId(r)
	return GoodsService.Content(r.GetCtx(), parames)
}

// 收藏商品
func (c *GoodsController) Collection(r *ghttp.Request) *response.JsonResponse {
	var parames *GoodsReq.Collection
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = token.GetLoginMemberId(r)
	return GoodsService.Collection(r.GetCtx(), parames)
}

// 热门搜索
func (c *GoodsController) HotSearch(r *ghttp.Request) *response.JsonResponse {
	var parames *GoodsReq.HotSearch
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = token.GetLoginMemberId(r)
	return GoodsService.HotSearch(r.GetCtx(), parames)
}

// 列表时，筛选数据
func (c *GoodsController) FilterData(r *ghttp.Request) *response.JsonResponse {
	var parames *GoodsReq.FilterData
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = token.GetLoginMemberId(r)
	return GoodsService.FilterData(r.GetCtx(), parames)
}
